
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>环境变量 · introduce</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gj">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../index.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="cors.html" />
    
    
    <link rel="prev" href="router.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    引导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    Vscode
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="jsdoc.html">
            
                <a href="jsdoc.html">
            
                    
                    Jsdoc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="webpack.html">
            
                <a href="webpack.html">
            
                    
                    Webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="router.html">
            
                <a href="router.html">
            
                    
                    路由和侧边栏
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="cors.html">
            
                <a href="cors.html">
            
                    
                    跨域问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="router-lazyload.html">
            
                <a href="router-lazyload.html">
            
                    
                    路由懒加载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="icons.html">
            
                <a href="icons.html">
            
                    
                    图标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="i18n.html">
            
                <a href="i18n.html">
            
                    
                    国际化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="eslint.html">
            
                <a href="eslint.html">
            
                    
                    ESLint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="permission.html">
            
                <a href="permission.html">
            
                    
                    权限验证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="style.html">
            
                <a href="style.html">
            
                    
                    样式
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >环境变量</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x73AF;&#x5883;&#x53D8;&#x91CF;">&#x73AF;&#x5883;&#x53D8;&#x91CF;</h2>
<p>&#x57FA;&#x4E8E; <code>vue-cli</code>&#x6765;&#x8FDB;&#x884C;&#x6784;&#x5EFA;&#xFF0C;&#x6240;&#x4EE5;&#x6240;&#x6709;&#x7684;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x914D;&#x7F6E;&#x90FD;&#x662F;&#x57FA;&#x4E8E;<code>vue-cli</code>&#x6765;&#x5B9E;&#x73B0;&#x548C;&#x63A7;&#x5236;&#x7684;&#x3002;</p>
<p><a href="https://cli.vuejs.org/zh/guide/mode-and-env.html" target="_blank">&#x5B98;&#x65B9;&#x6587;&#x6863;</a></p>
<pre class="language-"><code class="lang-text">.env                # &#x5728;&#x6240;&#x6709;&#x7684;&#x73AF;&#x5883;&#x4E2D;&#x88AB;&#x8F7D;&#x5165;
.env.[mode]         # &#x53EA;&#x5728;&#x6307;&#x5B9A;&#x7684;&#x6A21;&#x5F0F;&#x4E2D;&#x88AB;&#x8F7D;&#x5165;
</code></pre>
<p>&#x4E00;&#x4E2A;&#x73AF;&#x5883;&#x6587;&#x4EF6;&#x53EA;&#x5305;&#x542B;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x7684;&#x201C;&#x952E;=&#x503C;&#x201D;&#x5BF9;&#xFF1A;</p>
<pre class="language-"><code class="lang-text">FOO=bar
VUE_APP_SECRET=secret
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF01;&#xFF01;&#xFF01;</p>
<p>&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x5FC5;&#x987B;&#x4EE5;<code>VUE_APP_</code>&#x4E3A;&#x5F00;&#x5934;&#x3002;&#x5982;:<code>VUE_APP_API</code>&#x3001;<code>VUE_APP_TITLE</code></p>
<p>&#x4F60;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5982;&#x4E0B;&#x65B9;&#x5F0F;&#x83B7;&#x53D6;:</p>
<pre class="language-"><code class="lang-js">console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span>VUE_APP_xxxx<span class="token punctuation">)</span>
</code></pre>
<p>&#x9664;&#x4E86; <code>VUE_APP_*</code> &#x53D8;&#x91CF;&#x4E4B;&#x5916;&#xFF0C;&#x5728;&#x4F60;&#x7684;&#x5E94;&#x7528;&#x4EE3;&#x7801;&#x4E2D;&#x59CB;&#x7EC8;&#x53EF;&#x7528;&#x7684;&#x8FD8;&#x6709;&#x4E24;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x53D8;&#x91CF;&#xFF1A;</p>
<ul>
<li><code>NODE_ENV</code> - &#x4F1A;&#x662F; &quot;development&quot;&#x3001;&quot;production&quot; &#x6216; &quot;test&quot; &#x4E2D;&#x7684;&#x4E00;&#x4E2A;&#x3002;&#x5177;&#x4F53;&#x7684;&#x503C;&#x53D6;&#x51B3;&#x4E8E;&#x5E94;&#x7528;&#x8FD0;&#x884C;&#x7684;&#x6A21;&#x5F0F;&#x3002;</li>
<li><code>BASE_URL</code> - &#x4F1A;&#x548C; <code>vue.config.js</code> &#x4E2D;&#x7684; <code>publicPath</code> &#x9009;&#x9879;&#x76F8;&#x7B26;&#xFF0C;&#x5373;&#x4F60;&#x7684;&#x5E94;&#x7528;&#x4F1A;&#x90E8;&#x7F72;&#x5230;&#x7684;&#x57FA;&#x7840;&#x8DEF;&#x5F84;&#x3002;</li>
</ul>
<h3 id="&#x6784;&#x5EFA;&#x76F8;&#x5173;">&#x6784;&#x5EFA;&#x76F8;&#x5173;</h3>
<p>&#x9664;&#x4E86;&#x4E00;&#x4E9B;&#x5199;&#x5728;<code>.env</code>&#x7684;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x4E4B;&#x5916;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x6784;&#x5EFA;&#x548C;&#x90E8;&#x7F72;&#x76F8;&#x5173;&#x7684;&#x53D8;&#x91CF;&#x90FD;&#x662F;&#x9700;&#x8981;&#x5728;<code>vue.config.js</code>&#x4E2D;&#x914D;&#x7F6E;&#x7684;&#x3002;</p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>process.env.NODE_ENV</code>&#x6765;&#x6267;&#x884C;&#x5224;&#x65AD;&#x73AF;&#x5883;&#xFF0C;&#x6765;&#x8BBE;&#x7F6E;&#x4E0D;&#x540C;&#x7684;&#x53C2;&#x6570;&#x3002;</p>
<p>&#x5177;&#x4F53;&#x4EE3;&#x7801;&#x53EF;&#x501F;&#x9274;<a href="https://github.com/PanJiaChen/vue-element-admin/blob/master/vue.config.js" target="_blank">vue.config.js</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="router.html" class="navigation navigation-prev " aria-label="Previous page: 路由和侧边栏">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="cors.html" class="navigation navigation-next " aria-label="Next page: 跨域问题">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"环境变量","level":"1.6","depth":1,"next":{"title":"跨域问题","level":"1.7","depth":1,"path":"src/cors.md","ref":"src/cors.md","articles":[]},"previous":{"title":"路由和侧边栏","level":"1.5","depth":1,"path":"src/router.md","ref":"src/router.md","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","-lunr","-search","search-pro","-highlight","prism","livereload"],"styles":{"website":"index.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"expandable-chapters":{},"search-pro":{},"livereload":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Gj","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"introduce","language":"zh-hans","gitbook":"3.2.3","description":"项目搭建、规范、使用示例介绍"},"file":{"path":"src/env.md","mtime":"2020-07-29T02:59:31.168Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-29T07:02:36.580Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

